<?php
	$type = $_POST['msg'];
	$x = $_POST['kw'];
	include("conn.php");
	if($type!=""){
		$stmt = $db->prepare("select * from file where type=? and (name like ? or subject like ? or year like ? or uploadtime like ?)");
		$stmt->execute(array($type,"%$x%","%$x%","%$x%","%x%"));
	}
	else if($x!=""){
		$stmt = $db->prepare("select * from file where name like ? or subject like ? or year like ? or uploadtime like ?");
		$stmt->execute("%$x%","%$x%","%$x%","%x%");
	}
	else{
		$stmt = $db->prepare("select * from file");
		$stmt->execute();
	}	
	$x = array();
	while($result = $stmt->fetch(PDO::FETCH_ASSOC)){
		$x[] = $result;
	}
	echo json_encode($x);
?>